package com.che.software.testato.web.controller;

import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ActionEvent;
import javax.faces.model.SelectItem;
import javax.imageio.ImageIO;

import org.apache.log4j.Logger;
import org.primefaces.event.NodeSelectEvent;
import org.primefaces.model.DefaultStreamedContent;
import org.primefaces.model.DefaultTreeNode;
import org.primefaces.model.StreamedContent;
import org.primefaces.model.TreeNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.che.software.testato.business.ActionManager;
import com.che.software.testato.business.ActivityManager;
import com.che.software.testato.business.ElementManager;
import com.che.software.testato.business.IntentionManager;
import com.che.software.testato.business.ItemManager;
import com.che.software.testato.business.MapDiagramManager;
import com.che.software.testato.business.ProceduralDiagramManager;
import com.che.software.testato.business.TransitionManager;
import com.che.software.testato.business.VariantManager;
import com.che.software.testato.business.exception.ActionCreationManagerException;
import com.che.software.testato.business.exception.ActionSearchManagerException;
import com.che.software.testato.business.exception.ActivitySearchManagerException;
import com.che.software.testato.business.exception.ElementCreationManagerException;
import com.che.software.testato.business.exception.ElementSearchManagerException;
import com.che.software.testato.business.exception.IntentionSearchManagerException;
import com.che.software.testato.business.exception.ItemSearchManagerException;
import com.che.software.testato.business.exception.ItemUpdateManagerException;
import com.che.software.testato.business.exception.TransitionSearchManagerException;
import com.che.software.testato.business.exception.VariantCreationManagerException;
import com.che.software.testato.business.exception.VariantSearchManagerException;
import com.che.software.testato.business.exception.VariantUpdateManagerException;
import com.che.software.testato.domain.entity.Activity;
import com.che.software.testato.domain.entity.Element;
import com.che.software.testato.domain.entity.Hierarchy;
import com.che.software.testato.domain.entity.Intention;
import com.che.software.testato.domain.entity.Item;
import com.che.software.testato.domain.entity.MapArrow;
import com.che.software.testato.domain.entity.ProceduralArrow;
import com.che.software.testato.domain.entity.Section;
import com.che.software.testato.domain.entity.Transition;
import com.che.software.testato.domain.entity.Variant;
import com.che.software.testato.domain.entity.creation.ElementCreation;
import com.che.software.testato.domain.entity.creation.TransitionCreation;
import com.che.software.testato.domain.entity.search.ElementSearch;
import com.che.software.testato.domain.entity.search.IntentionSearch;
import com.che.software.testato.domain.entity.search.ItemSearch;
import com.che.software.testato.domain.entity.search.TransitionSearch;
import com.che.software.testato.domain.entity.search.VariantSearch;
import com.che.software.testato.domain.enumeration.VariantTypes;
import com.che.software.testato.domain.enumeration.creation.ElementCreationTypes;
import com.che.software.testato.util.ColorUtil;
import com.che.software.testato.util.jsf.faces.LocaleUtil;
import com.che.software.testato.util.jung.DiagramGraphistUtil;
import com.che.software.testato.util.jung.enumeration.DrawingAlgorithm;
import com.che.software.testato.web.controller.acontroller.AbstractController;

import edu.uci.ics.jung.graph.DirectedGraph;

/**
 * Controller used to manage the hierarchies visualisation.
 * 
 * @author Clement HELIOU (clement.heliou@che-software.com).
 * @copyright Che Software.
 * @license GNU General Public License.
 * @see AbstractController, Serializable.
 * @since July, 2011.
 * 
 *        This file is part of Testato.
 * 
 *        Testato is free software: you can redistribute it and/or modify it
 *        under the terms of the GNU General Public License as published by the
 *        Free Software Foundation, either version 3 of the License, or (at your
 *        option) any later version.
 * 
 *        Testato is distributed in the hope that it will be useful, but WITHOUT
 *        ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 *        FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
 *        for more details.
 * 
 *        You should have received a copy of the GNU General Public License
 *        along with Testato. If not, see <http://www.gnu.org/licenses/>.
 * 
 *        Testato's logo is a creation of Arrioch
 *        (http://arrioch.deviantart.com/) and it's distributed under the terms
 *        of the Creative Commons License.
 */
@Component("hierarchyVisualisationController")
@ManagedBean(name = "hierarchyVisualisationController")
@Scope("session")
@SessionScoped
public class HierarchyVisualisationController extends AbstractController implements Serializable {

	/**
	 * Constants.
	 */
	private static final Logger LOGGER = Logger.getLogger(HierarchyVisualisationController.class);
	private static final long serialVersionUID = 8226534803409493026L;
	private static final String NODE_TYPE_FAILURE_VARIANT = "fva", NODE_TYPE_ITEM = "ite", NODE_TYPE_MAP = "map", NODE_TYPE_PROCEDURAL = "pro", NODE_TYPE_SUCCESS_VARIANT = "sva";

	/**
	 * Members.
	 */
	@Autowired
	private transient ActionManager actionManager;
	@Autowired
	private transient ActivityManager activityManager;
	private boolean errorIntentionOrSectionNumber = false, errorIsolatedExclusiveSection = false, errorIsolatedIntention = false, errorMaxIterationNumberMissing = false, errorMissingIntention = false, errorStartIntention = false, errorStartOrStopIntentionMissing = false, errorStopIntention = false;
	private boolean errorElementOrTransitionNumber = false, errorIsolatedElement = false, errorMissingElement = false, errorMissingStartOrStopElement = false, errorMultipleSources = false, errorMultipleTransitions = false, errorOptionMissingAfterChoice = false, errorSourceEqualsTarget = false, errorStartElement = false, errorStopElement = false, errorTransitionNumberOnChoice = false, errorTransitionNumberOnJoin = false;
	private Boolean actionExistingFromCurrentMap, elementExistingFromCurrentDiagram, variantsExistingFromCurrentDiagram;
	private DrawingAlgorithm currentMapAlgorithm = DrawingAlgorithm.KK, currentProceduralAlgorithm = DrawingAlgorithm.ISOM, currentVariantAlgorithm = DrawingAlgorithm.ISOM, oldMapAlgorithm = DrawingAlgorithm.KK, oldProceduralAlgorithm = DrawingAlgorithm.ISOM, oldVariantAlgorithm = DrawingAlgorithm.ISOM;
	private Element[] selectedElements, selectedVariantsElements;
	private ElementCreation elementToCollect = new ElementCreation();
	@Autowired
	private transient ElementManager elementManager;
	private Hierarchy currentHierarchy;
	private int currentActionPlanId, currentTestCaseId, currentVariantId;
	private Intention intentionToCollect = new Intention();
	private Intention[] selectedIntentions;
	@Autowired
	private transient IntentionManager intentionManager;
	private Item[] selectedItems;
	@Autowired
	private transient ItemManager itemManager;
	private List<Activity> activitiesToDescribe;
	private List<Element> elements, variantsElements;
	private List<ElementCreation> elementsToAdd;
	private List<Intention> intentionsToAdd, intentions;
	private List<Item> items;
	private List<Section> sectionsToAdd;
	private List<SelectItem> drawingAlgorithmsAsSelectItem, elementToAddTypesAsSelectItem;
	private List<Transition> transitions, variantsTransitions;
	private List<TransitionCreation> transitionsToAdd;
	private List<Variant> variants;
	@Autowired
	private transient MapDiagramManager mapDiagramManager;
	@Autowired
	private transient ProceduralDiagramManager proceduralDiagramManager;
	private Section sectionToCollect = new Section();
	private StreamedContent fullMapDiagram, fullProceduralDiagram, fullVariantDiagram, mapDiagram, proceduralDiagram, variantDiagram;
	private Transition[] selectedTransitions, selectedVariantsTransitions;
	private TransitionCreation transitionToCollect = new TransitionCreation();
	@Autowired
	private transient TransitionManager transitionManager;
	private TreeNode root, selectedNode;
	private Variant currentEditingVariant;
	@Autowired
	private transient VariantManager variantManager;

	/**
	 * Default Builder.
	 */
	public HierarchyVisualisationController() {
		super();
		elementsToAdd = new ArrayList<ElementCreation>();
		intentionsToAdd = new ArrayList<Intention>();
		sectionsToAdd = new ArrayList<Section>();
		transitionsToAdd = new ArrayList<TransitionCreation>();
	}

	/**
	 * Getter for the element to add types as a list of SelectItem (to be used
	 * in the selectOneMenu items).
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @return the resulting object list.
	 * @since July, 2011.
	 */
	public List<SelectItem> getElementToAddTypesAsSelectItem() {
		if (null == elementToAddTypesAsSelectItem) {
			LOGGER.debug("getElementToAddTypesAsSelectItem(): initialization.");
			elementToAddTypesAsSelectItem = new ArrayList<SelectItem>();
			elementToAddTypesAsSelectItem.add(new SelectItem(ElementCreationTypes.ACTIVITY, LocaleUtil.getResourceBundleStringByName(BUNDLE_MESSAGE_ACTIVITY)));
			elementToAddTypesAsSelectItem.add(new SelectItem(ElementCreationTypes.CHOICE, LocaleUtil.getResourceBundleStringByName(BUNDLE_MESSAGE_CHOICE)));
			elementToAddTypesAsSelectItem.add(new SelectItem(ElementCreationTypes.JOIN, LocaleUtil.getResourceBundleStringByName(BUNDLE_MESSAGE_JOIN)));
			elementToAddTypesAsSelectItem.add(new SelectItem(ElementCreationTypes.NEGATIVE_END, LocaleUtil.getResourceBundleStringByName(BUNDLE_MESSAGE_NEGATIVE_END)));
			elementToAddTypesAsSelectItem.add(new SelectItem(ElementCreationTypes.POSITIVE_END, LocaleUtil.getResourceBundleStringByName(BUNDLE_MESSAGE_POSITIVE_END)));
			elementToAddTypesAsSelectItem.add(new SelectItem(ElementCreationTypes.START, LocaleUtil.getResourceBundleStringByName(BUNDLE_MESSAGE_START)));
		}
		return elementToAddTypesAsSelectItem;
	}

	/**
	 * Getter for the elements to add as a list of SelectItem (to be used in the
	 * selectOneMenu items).
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @return the resulting object list.
	 * @since July, 2011.
	 */
	public List<SelectItem> getElementsToAddAsSelectItem() {
		LOGGER.debug("getElementsToAddAsSelectItem().");
		List<SelectItem> elements = new ArrayList<SelectItem>();
		for (ElementCreation element : elementsToAdd) {
			elements.add(new SelectItem(element.getLabel(), element.getLabel()));
		}
		return elements;
	}

	/**
	 * Getter for the intentions to add as a list of SelectItem (to be used in
	 * the selectOneMenu items).
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @return the resulting object list.
	 * @since July, 2011.
	 */
	public List<SelectItem> getIntentionsToAddAsSelectItem() {
		LOGGER.debug("getIntentionsToAddAsSelectItem().");
		List<SelectItem> intentions = new ArrayList<SelectItem>();
		for (Intention intention : intentionsToAdd) {
			intentions.add(new SelectItem(intention.getLabel()));
		}
		return intentions;
	}

	/**
	 * Initializes the element to collect object.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @param e the event launched on this action.
	 * @since July, 2011.
	 */
	public String initElementToCreate() {
		LOGGER.debug("initElementToCreate().");
		elementToCollect = new ElementCreation();
		return null;
	}

	/**
	 * Initializes the errors fields for the map creation.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @since July, 2011.
	 */
	public void initErrorsFields() {
		LOGGER.debug("initErrorsFields().");
		errorIntentionOrSectionNumber = false;
		errorIsolatedExclusiveSection = false;
		errorIsolatedIntention = false;
		errorMaxIterationNumberMissing = false;
		errorMissingIntention = false;
		errorStartIntention = false;
		errorStartOrStopIntentionMissing = false;
		errorStopIntention = false;
	}

	/**
	 * Initializes the intention to collect object.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @param e the event launched on this action.
	 * @since July, 2011.
	 */
	public String initIntentionToCollect() {
		LOGGER.debug("initIntentionToCollect().");
		intentionToCollect = new Intention();
		return null;
	}

	/**
	 * Initializes the errors fields for the procedural diagram creation.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @since July, 2011.
	 */
	public void initProceduralErrorsFields() {
		LOGGER.debug("initProceduralErrorsFields().");
		errorElementOrTransitionNumber = false;
		errorIsolatedElement = false;
		errorMissingElement = false;
		errorMissingStartOrStopElement = false;
		errorMultipleSources = false;
		errorMultipleTransitions = false;
		errorOptionMissingAfterChoice = false;
		errorSourceEqualsTarget = false;
		errorStartElement = false;
		errorStopElement = false;
		errorTransitionNumberOnChoice = false;
		errorTransitionNumberOnJoin = false;
	}

	/**
	 * Initializes the section to collect object.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @param e the event launched on this action.
	 * @since July, 2011.
	 */
	public String initSectionToCollect() {
		LOGGER.debug("initSectionToCollect().");
		sectionToCollect = new Section();
		return null;
	}

	/**
	 * Initializes the transition to collect object.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @param e the event launched on this action.
	 * @since July, 2011.
	 */
	public String initTransitionToCollect() {
		LOGGER.debug("initTransitionToCollect().");
		transitionToCollect = new TransitionCreation();
		return null;
	}

	/**
	 * Checks if the selected node is a failure variant.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @return true if the selected node is a failure variant, else false.
	 * @since July, 2011.
	 */
	public boolean isSelectedNodeFailureVariant() {
		LOGGER.debug("isSelectedNodeFailureVariant().");
		return (null == selectedNode) ? false : (selectedNode.getType().equalsIgnoreCase(NODE_TYPE_FAILURE_VARIANT)) ? true : false;
	}

	/**
	 * Checks if the selected node is an item.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @return true if the selected node is an item, else false.
	 * @since July, 2011.
	 */
	public boolean isSelectedNodeItem() {
		LOGGER.debug("isSelectedNodeItem().");
		return (null == selectedNode) ? false : (selectedNode.getType().equalsIgnoreCase(NODE_TYPE_ITEM)) ? true : false;
	}

	/**
	 * Checks if the selected node is a map.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @return true if the selected node is a map, else false.
	 * @since July, 2011.
	 */
	public boolean isSelectedNodeMap() {
		LOGGER.debug("isSelectedNodeMap().");
		return (null == selectedNode) ? false : (selectedNode.getData() instanceof String || selectedNode.getType().equalsIgnoreCase(NODE_TYPE_MAP)) ? true : false;
	}

	/**
	 * Checks if the selected node is a procedural diagram.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @return true if the selected node is a procedural diagram, else false.
	 * @since July, 2011.
	 */
	public boolean isSelectedNodeProceduralDiagram() {
		LOGGER.debug("isSelectedNodeProceduralDiagram().");
		return (null == selectedNode) ? false : (selectedNode.getType().equalsIgnoreCase(NODE_TYPE_PROCEDURAL)) ? true : false;
	}

	/**
	 * Checks if the selected node is a success variant.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @return true if the selected node is a success variant, else false.
	 * @since July, 2011.
	 */
	public boolean isSelectedNodeSuccessVariant() {
		LOGGER.debug("isSelectedNodeSuccessVariant().");
		return (null == selectedNode) ? false : (selectedNode.getType().equalsIgnoreCase(NODE_TYPE_SUCCESS_VARIANT)) ? true : false;
	}

	/**
	 * Redirection processed on the activity documentation launching.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @return the resulting url to reach.
	 * @since July, 2011.
	 */
	public String onActivityDocumentation() {
		LOGGER.debug("onActivityDocumentation().");
		return "activityDocumentation.xhtml?faces-redirect=true";
	}

	/**
	 * Event listener to finalize the map to be built.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @param event the event launched on finalize action.
	 * @since July, 2011.
	 */
	public void onFinalizeMap(ActionEvent event) {
		LOGGER.debug("onFinalizeMap().");
		initErrorsFields();
		if (intentionsToAdd.size() < 3 || sectionsToAdd.size() < 2) {
			errorIntentionOrSectionNumber = true;
			return;
		}
		if (!areExistingIntentions()) {
			errorMissingIntention = true;
			return;
		}
		if (!areStartAndStopIntentionsPresent()) {
			errorStartOrStopIntentionMissing = true;
			return;
		}
		if (!isStartIntentionSource()) {
			errorStartIntention = true;
			return;
		}
		if (!isStopIntentionTarget()) {
			errorStopIntention = true;
			return;
		}
		for (Intention intention : intentionsToAdd) {
			if (!intention.getLabel().equalsIgnoreCase("Start") && !intention.getLabel().equalsIgnoreCase("Début") && !intention.getLabel().equalsIgnoreCase("Stop") && !intention.getLabel().equalsIgnoreCase("Fin") && isIsolatedIntention(intention.getLabel())) {
				errorIsolatedIntention = true;
				return;
			}
		}
		for (Section section : sectionsToAdd) {
			if ((section.getSourceIntention().equalsIgnoreCase(section.getTargetIntention()) && 0 == section.getMaxIterationNumber()) || null != isReverseSectionExists(section) && 0 == isReverseSectionExists(section).getMaxIterationNumber() && 0 == section.getMaxIterationNumber()) {
				errorMaxIterationNumberMissing = true;
				return;
			}
		}
		for (Section section : sectionsToAdd) {
			if (section.isExclusive() && !isAnotherExclusiveSectionExists(section.getStrategyLabel())) {
				errorIsolatedExclusiveSection = true;
				return;
			}
		} // All is alright: the map creation can be done.
		try {
			actionManager.createMap(currentActionPlanId, intentionsToAdd, sectionsToAdd);
			actionExistingFromCurrentMap = null;
			intentionsToAdd = new ArrayList<Intention>();
			intentionToCollect = new Intention();
			root = null; // To trigger the data loading.
			sectionsToAdd = new ArrayList<Section>();
			sectionToCollect = new Section();
			selectedNode = null;
		} catch (ActionCreationManagerException e) {
			LOGGER.error("Error during the map creation.", e);
		}
	}

	/**
	 * Event listener to finalize the procedural diagram to be built.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @param event the event launched on finalize action.
	 * @since July, 2011.
	 */
	public void onFinalizeProceduralDiagram(ActionEvent event) {
		LOGGER.debug("onFinalizeProceduralDiagram().");
		initProceduralErrorsFields();
		if (elementsToAdd.size() < 4 || transitionsToAdd.size() < 3) {
			errorElementOrTransitionNumber = true;
			return;
		}
		if (!areStartAndStopElementsPresent()) {
			errorMissingStartOrStopElement = true;
			return;
		}
		if (!isStartElementSource()) {
			errorStartElement = true;
			return;
		}
		if (!isStopElementSource()) {
			errorStopElement = true;
			return;
		}
		if (!areExistingElements()) {
			errorMissingElement = true;
			return;
		}
		for (ElementCreation element : elementsToAdd) {
			if (!element.getLabel().equalsIgnoreCase("Start") && !element.getLabel().equalsIgnoreCase("Début") && !element.getLabel().endsWith("end") && !element.getLabel().startsWith("Fin")) {
				if (isIsolatedElement(element.getLabel())) {
					errorIsolatedElement = true;
					return;
				}
			}
		}
		if (!areElementsWithUniqueSource()) {
			errorMultipleSources = true;
			return;
		}
		if (!areChoiceOptionsSetted()) {
			errorOptionMissingAfterChoice = true;
			return;
		}
		if (isSourceElementEqualsTargetElement()) {
			errorSourceEqualsTarget = true;
			return;
		}
		if (!areTransitionsUnique()) {
			errorMultipleTransitions = true;
			return;
		}
		if (!areChoiceWithTransitions()) {
			errorTransitionNumberOnChoice = true;
			return;
		}
		if (!areJoinWithTransitions()) {
			errorTransitionNumberOnJoin = true;
			return;
		}
		try {
			elementManager.createDiagram(currentTestCaseId, elementsToAdd, transitionsToAdd);
			elementExistingFromCurrentDiagram = false;
			elementsToAdd = new ArrayList<ElementCreation>();
			elementToCollect = new ElementCreation();
			root = null; // To trigger the data loading.
			selectedNode = null;
			transitionsToAdd = new ArrayList<TransitionCreation>();
			transitionToCollect = new TransitionCreation();
			variantsExistingFromCurrentDiagram = null;
		} catch (ElementCreationManagerException e) {
			LOGGER.error("Error during the procedural diagram creation.", e);
		}
	}

	/**
	 * Event listener to redraw the full map diagram.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @param event the event launched on redrawing action.
	 * @since July, 2011.
	 */
	public void onFullMapDrawing(ActionEvent event) {
		LOGGER.debug("onFullMapDrawing().");
		if (!currentMapAlgorithm.equals(oldMapAlgorithm)) {
			LOGGER.debug("onFullMapDrawing(): redrawing.");
			oldMapAlgorithm = currentMapAlgorithm;
			fullMapDiagram = null; // To trigger the full map diagram loading.
		}
	}

	/**
	 * Event listener to redraw the full procedural diagram.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @param event the event launched on redrawing action.
	 * @since July, 2011.
	 */
	public void onFullProceduralDrawing(ActionEvent event) {
		LOGGER.debug("onFullProceduralDrawing().");
		if (!currentProceduralAlgorithm.equals(oldProceduralAlgorithm)) {
			LOGGER.debug("onFullProceduralDrawing(): redrawing.");
			oldProceduralAlgorithm = currentProceduralAlgorithm;
			fullProceduralDiagram = null;
		}
	}

	/**
	 * Event listener to redraw the full variant diagram.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @param event the event launched on redrawing action.
	 * @since July, 2011.
	 */
	public void onFullVariantDrawing(ActionEvent event) {
		LOGGER.debug("onFullVariantDrawing().");
		if (!currentVariantAlgorithm.equals(oldVariantAlgorithm)) {
			LOGGER.debug("onFullVariantDrawing(): redrawing.");
			oldVariantAlgorithm = currentVariantAlgorithm;
			fullVariantDiagram = null;
		}
	}

	/**
	 * Event listener to generate the variants of a procedural diagram.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @param event the event launched on redrawing action.
	 * @since July, 2011.
	 */
	public void onGenerateVariants(ActionEvent event) {
		LOGGER.debug("onGenerateVariants");
		try {
			variantManager.createVariantsFromTestCaseId(currentTestCaseId, proceduralDiagramManager.generateVariantsFromProceduralDiagram(proceduralDiagramManager.createProceduralDiagramFromElementsAndTransitions(getElements(), getTransitions())));
			activitiesToDescribe = null; // To trigger the data loading.
			elements = null; // To trigger the data loading.
			fullProceduralDiagram = null; // To trigger the map loading.
			proceduralDiagram = null; // To trigger the diagram loading.
			root = null; // To trigger the data loading.
			selectedNode = null;
			transitions = null;
			variantsElements = null;
			variantsTransitions = null;
			variantsExistingFromCurrentDiagram = null;
		} catch (VariantCreationManagerException e) {
			LOGGER.error("Error during the variants generation.", e);
		}
	}

	/**
	 * Node select event listener to update the right part of the page layout.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @param event the event launched on node selection.
	 * @since July, 2011.
	 */
	public void onNodeSelectEvent(NodeSelectEvent event) {
		LOGGER.debug("onNodeSelectEvent(" + event.getTreeNode().getData().toString() + ").");
		actionExistingFromCurrentMap = null;
		elementExistingFromCurrentDiagram = null;
		currentActionPlanId = (null == selectedNode || !selectedNode.getType().equalsIgnoreCase(NODE_TYPE_MAP)) ? 0 : (selectedNode.getData() instanceof String) ? currentHierarchy.getActionPlanId() : ((Item) selectedNode.getData()).getActionPlanId();
		currentTestCaseId = (null == selectedNode || !selectedNode.getType().equalsIgnoreCase(NODE_TYPE_PROCEDURAL)) ? 0 : ((Item) selectedNode.getData()).getTestCaseId();
		currentVariantId = (null == selectedNode || (!selectedNode.getType().equalsIgnoreCase(NODE_TYPE_FAILURE_VARIANT) && !selectedNode.getType().equalsIgnoreCase(NODE_TYPE_SUCCESS_VARIANT))) ? 0 : ((Variant) selectedNode.getData()).getVariantId();
		variantsExistingFromCurrentDiagram = null;
		if (null != selectedNode && selectedNode.getType().equalsIgnoreCase(NODE_TYPE_MAP)) {
			fullMapDiagram = null; // To trigger the map loading.
			intentions = null; // To trigger the data loading.
			items = null;
			mapDiagram = null; // To trigger the map loading.
		}
		if (null != selectedNode && selectedNode.getType().equalsIgnoreCase(NODE_TYPE_PROCEDURAL)) {
			activitiesToDescribe = null; // To trigger the data loading.
			currentEditingVariant = null;
			elements = null; // To trigger the data loading.
			fullProceduralDiagram = null; // To trigger the map loading.
			transitions = null;
			proceduralDiagram = null; // To trigger the diagram loading.
			variants = null;
		}
		if (null != selectedNode && (selectedNode.getType().equalsIgnoreCase(NODE_TYPE_FAILURE_VARIANT) || selectedNode.getType().equalsIgnoreCase(NODE_TYPE_SUCCESS_VARIANT))) {
			fullVariantDiagram = null;
			variantDiagram = null;
			variantsElements = null;
			variantsTransitions = null;
		}
	}

	/**
	 * Event listener for an item operationalization.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @param event the event launched.
	 * @since July, 2011.
	 */
	public void onOperationalizeItem(ActionEvent event) {
		LOGGER.debug("onOperationalizeItem().");
		try {
			itemManager.operationalizeItem(((Item) selectedNode.getData()).getItemId());
			root = null; // To trigger the data loading.
			selectedNode = null;
		} catch (ItemUpdateManagerException e) {
			LOGGER.error("Error during the item operationalization.", e);
		}
	}

	/**
	 * Event listener for an item refinement.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @param event the event launched.
	 * @since July, 2011.
	 */
	public void onRefineItem(ActionEvent event) {
		LOGGER.debug("onRefineItem().");
		try {
			itemManager.refineItem(((Item) selectedNode.getData()).getItemId());
			root = null; // To trigger the data loading.
			selectedNode = null;
		} catch (ItemUpdateManagerException e) {
			LOGGER.error("Error during the item refinement.", e);
		}
	}

	/**
	 * Event listener for a variant update.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @return null because none navigation is requested.
	 * @since July, 2011.
	 */
	public String onVariantUpdate() {
		LOGGER.debug("onVariantUpdate().");
		try {
			variantManager.updateVariant(currentEditingVariant);
			if (null != currentEditingVariant.getLabel() && !"".equalsIgnoreCase(currentEditingVariant.getLabel())) {
				items = null;
				root = null;
				variants = null;
			}
		} catch (VariantUpdateManagerException e) {
			LOGGER.error("Error during a variant update.", e);
		}
		return null;
	}

	/**
	 * Checks if every transition which has a choice point as source element has
	 * a label.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @return true if every transition which has a choice point as source
	 *         element has a label, else false.
	 * @since July, 2011.
	 */
	private boolean areChoiceOptionsSetted() {
		LOGGER.debug("areChoiceOptionsSetted().");
		for (ElementCreation element : elementsToAdd) {
			if (element.getType().equals(ElementCreationTypes.CHOICE)) {
				for (TransitionCreation transition : transitionsToAdd) {
					if (transition.getSource().equalsIgnoreCase(element.getLabel()) && (null == transition.getLabel() || "".equalsIgnoreCase(transition.getLabel()))) {
						return false;
					}
				}
			}
		}
		return true;
	}

	/**
	 * Checks if every choice element is the source of at least 2 transitions.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @return true if every choice element is the source of at least 2
	 *         transitions, else false.
	 * @since July, 2011.
	 */
	private boolean areChoiceWithTransitions() {
		LOGGER.debug("areChoiceWithTransitions().");
		for (ElementCreation element : elementsToAdd) {
			if (element.getType().equals(ElementCreationTypes.CHOICE)) {
				int cpt = 0;
				for (TransitionCreation transition : transitionsToAdd) {
					if (transition.getSource().equals(element.getLabel())) {
						cpt++;
					}
				}
				if (cpt < 2) {
					return false;
				}
			}
		}
		return true;
	}

	/**
	 * Checks if every element (except the choice points) is used at most one
	 * time as source.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @return true if every element (except the choice points) is used at most
	 *         one time as source, else false.
	 * @since July, 2011.
	 */
	private boolean areElementsWithUniqueSource() {
		LOGGER.debug("areElementsWithUniqueSource().");
		for (ElementCreation element : elementsToAdd) {
			if (!element.getType().equals(ElementCreationTypes.CHOICE)) {
				int cpt = 0;
				for (TransitionCreation transition : transitionsToAdd) {
					if (transition.getSource().equalsIgnoreCase(element.getLabel())) {
						cpt++;
						if (cpt > 1) {
							return false;
						}
					}
				}
				if (cpt > 1) {
					return false;
				}
			}
		}
		return true;
	}

	/**
	 * Checks if every element used in the transitions is stil existing.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @return true if every element used is present, else false.
	 * @since July, 2011.
	 */
	private boolean areExistingElements() {
		LOGGER.debug("areExistingElements().");
		for (TransitionCreation transition : transitionsToAdd) {
			boolean source = false, target = false;
			for (ElementCreation element : elementsToAdd) {
				if (element.getLabel().equalsIgnoreCase(transition.getSource())) {
					source = true;
				}
				if (element.getLabel().equalsIgnoreCase(transition.getTarget())) {
					target = true;
				}
			}
			if (!source || !target) {
				return false;
			}
		}
		return true;
	}

	/**
	 * Checks if every intention used in the sections is stil existing.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @return true if every element used is present, else false.
	 * @since July, 2011.
	 */
	private boolean areExistingIntentions() {
		LOGGER.debug("areExistingIntentions().");
		for (Section section : sectionsToAdd) {
			boolean source = false, target = false;
			for (Intention intention : intentionsToAdd) {
				if (intention.getLabel().equalsIgnoreCase(section.getSourceIntention())) {
					source = true;
				}
				if (intention.getLabel().equalsIgnoreCase(section.getTargetIntention())) {
					target = true;
				}
			}
			if (!source || !target) {
				return false;
			}
		}
		return true;
	}

	/**
	 * Checks if every join element is the target of at least 2 transitions.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @return true if every join element is the target of at least 2
	 *         transitions, else false.
	 * @since July, 2011.
	 */
	private boolean areJoinWithTransitions() {
		LOGGER.debug("areJoinWithTransitions().");
		for (ElementCreation element : elementsToAdd) {
			if (element.getType().equals(ElementCreationTypes.JOIN)) {
				int cpt = 0;
				for (TransitionCreation transition : transitionsToAdd) {
					if (transition.getTarget().equals(element.getLabel())) {
						cpt++;
					}
				}
				if (cpt < 2) {
					return false;
				}
			}
		}
		return true;
	}

	/**
	 * Checks if the start and stop elements are present in the list to be
	 * created.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @return true if the start and stop elements are present, else false.
	 * @since July, 2011.
	 */
	private boolean areStartAndStopElementsPresent() {
		LOGGER.debug("areStartAndStopElementsPresent().");
		boolean start = false, nEnd = false, pEnd = false;
		for (ElementCreation element : elementsToAdd) {
			if (element.getType().equals(ElementCreationTypes.START) && (element.getLabel().equalsIgnoreCase("Start") || element.getLabel().equalsIgnoreCase("Début"))) {
				start = true;
			}
			if (element.getType().equals(ElementCreationTypes.NEGATIVE_END) && (element.getLabel().equalsIgnoreCase("Negative end") || element.getLabel().equalsIgnoreCase("Fin négative"))) {
				nEnd = true;
			}
			if (element.getType().equals(ElementCreationTypes.POSITIVE_END) && (element.getLabel().equalsIgnoreCase("Positive end") || element.getLabel().equalsIgnoreCase("Fin positive"))) {
				pEnd = true;
			}
		}
		return nEnd && pEnd && start;
	}

	/**
	 * Checks if the start and stop intentions are present in the list to be
	 * created.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @return true if the start and stop intentions are present, else false.
	 * @since July, 2011.
	 */
	private boolean areStartAndStopIntentionsPresent() {
		LOGGER.debug("areStartAndStopIntentionsPresent().");
		boolean start = false, stop = false;
		for (Intention intention : intentionsToAdd) {
			if (intention.getLabel().equalsIgnoreCase("Start") || intention.getLabel().equalsIgnoreCase("Début")) {
				start = true;
			}
			if (intention.getLabel().equalsIgnoreCase("Stop") || intention.getLabel().equalsIgnoreCase("Fin")) {
				stop = true;
			}
		}
		return start && stop;
	}

	/**
	 * Checks if the transitions are unique (i.e. only one transition between
	 * the same source and target elements) in the diagram.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @return true if the transitions are unique, else false.
	 * @since July, 2011.
	 */
	private boolean areTransitionsUnique() {
		LOGGER.debug("areTransitionsUnique().");
		for (TransitionCreation transition : transitionsToAdd) {
			for (TransitionCreation otherTransition : transitionsToAdd) {
				if (transition.getSource().equalsIgnoreCase(otherTransition.getSource()) && transition.getTarget().equalsIgnoreCase(otherTransition.getTarget()) && !transition.getLabel().equalsIgnoreCase(otherTransition.getLabel())) {
					return false;
				}
			}
		}
		return true;
	}

	/**
	 * Checks if an other exclusive section exists for the source and target
	 * intentions of the given section.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @param sectionName the name of the exclusive section which is a member of
	 *        the cluster whose we search the other exclusives sections.
	 * @return true if an other exclusive section exists, else false.
	 * @since July, 2011.
	 */
	private boolean isAnotherExclusiveSectionExists(String sectionName) {
		LOGGER.debug("isAnotherExclusiveSectionExists(" + sectionName + ").");
		for (Section section : sectionsToAdd) {
			if (section.isExclusive() && !section.getStrategyLabel().equalsIgnoreCase(sectionName)) {
				return true;
			}
		}
		return false;
	}

	/**
	 * Checks if an element is isolated or not. An intention isn't isolated if
	 * it's source and target at least in one transition.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @param elementName the name of the element.
	 * @return true if the element is isolated, else false.
	 * @since July, 2011.
	 */
	private boolean isIsolatedElement(String elementName) {
		LOGGER.debug("isIsolatedElement(" + elementName + ").");
		boolean source = false, target = false;
		for (TransitionCreation transition : transitionsToAdd) {
			if (transition.getSource().equalsIgnoreCase(elementName)) {
				source = true;
			}
			if (transition.getTarget().equalsIgnoreCase(elementName)) {
				target = true;
			}
		}
		return !(source && target);
	}

	/**
	 * Checks if an intention is isolated or not. An intention isn't isolated if
	 * it's source and target at least in one section.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @param intentionName the name of the intention.
	 * @return true if the intention is isolated, else false.
	 * @since July, 2011.
	 */
	private boolean isIsolatedIntention(String intentionName) {
		LOGGER.debug("isIsolatedIntention(" + intentionName + ").");
		boolean source = false, target = false;
		for (Section section : sectionsToAdd) {
			if (section.getSourceIntention().equalsIgnoreCase(intentionName)) {
				source = true;
			}
			if (section.getTargetIntention().equalsIgnoreCase(intentionName)) {
				target = true;
			}
		}
		return !(source && target);
	}

	/**
	 * Checks if the reverse section of the given one exists.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @param intentionName the name of the intention.
	 * @return the reverse section if it's exists, else null.
	 * @since July, 2011.
	 */
	private Section isReverseSectionExists(Section section) {
		LOGGER.debug("isReverseSectionExists(" + section.getSourceIntention() + "," + section.getTargetIntention() + ").");
		for (Section otherSection : sectionsToAdd) {
			if (otherSection.getSourceIntention().equalsIgnoreCase(section.getTargetIntention()) && otherSection.getTargetIntention().equalsIgnoreCase(section.getSourceIntention())) {
				return otherSection;
			}
		}
		return null;
	}

	/**
	 * Checks if a transition contains the same element as source and target.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @return true if a transition has the same element as source and target,
	 *         else false.
	 * @since July, 2011.
	 */
	private boolean isSourceElementEqualsTargetElement() {
		LOGGER.debug("isSourceElementEqualsTargetElement().");
		for (TransitionCreation transition : transitionsToAdd) {
			if (transition.getSource().equalsIgnoreCase(transition.getTarget())) {
				return true;
			}
		}
		return false;
	}

	/**
	 * Checks if the start element is used at least one time as a source.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @return true if the start element is used at least one time as a source,
	 *         else false.
	 * @since July, 2011.
	 */
	private boolean isStartElementSource() {
		LOGGER.debug("isStartElementSource().");
		for (TransitionCreation transition : transitionsToAdd) {
			if (transition.getSource().equalsIgnoreCase("Start") || transition.getSource().equalsIgnoreCase("Début")) {
				return true;
			}
		}
		return false;
	}

	/**
	 * Checks if the start intention is used at least one time as source
	 * intention.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @return true if the start intention is used at least one time as source
	 *         intention, else false.
	 * @since July, 2011.
	 */
	private boolean isStartIntentionSource() {
		LOGGER.debug("isStartIntentionSource().");
		for (Section section : sectionsToAdd) {
			if (section.getSourceIntention().equalsIgnoreCase("Start") || section.getSourceIntention().equalsIgnoreCase("Début")) {
				return true;
			}
		}
		return false;
	}

	/**
	 * Checks if the stop element is used at least one time as a target.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @return true if the stop element is used at least one time as a target,
	 *         else false.
	 * @since July, 2011.
	 */
	private boolean isStopElementSource() {
		LOGGER.debug("isStopElementSource().");
		boolean nEnd = false, pEnd = false;
		for (TransitionCreation transition : transitionsToAdd) {
			if (transition.getTarget().equalsIgnoreCase("Negative end") || transition.getTarget().equalsIgnoreCase("Fin négative")) {
				nEnd = true;
			}
			if (transition.getTarget().equalsIgnoreCase("Positive end") || transition.getTarget().equalsIgnoreCase("Fin positive")) {
				pEnd = true;
			}
		}
		return nEnd && pEnd;
	}

	/**
	 * Checks if the stop intention is used at least one time as target
	 * intention.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @return true if the stop intention is used at least one time as target
	 *         intention, else false.
	 * @since July, 2011.
	 */
	private boolean isStopIntentionTarget() {
		LOGGER.debug("isStopIntentionTarget().");
		for (Section section : sectionsToAdd) {
			if (section.getTargetIntention().equalsIgnoreCase("Stop") || section.getTargetIntention().equalsIgnoreCase("Fin")) {
				return true;
			}
		}
		return false;
	}

	/**
	 * Recursive method used to build the hierarchy tree. For a given action
	 * plan, searches all contained items and add them. If the added item is a
	 * test case, add the possible variants. If the added item is an action
	 * plan, makes a recursive call.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @param parentActionPlanId the parent action plan id.
	 * @param parentNode the parent node (to add the generated nodes).
	 * @since July, 2011.
	 * @throws ItemSearchManagerException if an error occurs during an item
	 *         search.
	 * @throws VariantSearchManagerException if an error occurs during a variant
	 *         search.
	 */
	private void getTreeFromActionPlan(int parentActionPlanId, TreeNode parentNode) throws ItemSearchManagerException, VariantSearchManagerException {
		LOGGER.debug("getTreeFromActionPlan(" + parentActionPlanId + ").");
		for (Item item : itemManager.searchItem(new ItemSearch(parentActionPlanId))) {
			TreeNode itemNode = new DefaultTreeNode((0 != item.getActionPlanId()) ? NODE_TYPE_MAP : (0 != item.getTestCaseId()) ? NODE_TYPE_PROCEDURAL : NODE_TYPE_ITEM, item, parentNode);
			if (0 != item.getTestCaseId()) { // Test cases.
				for (Variant variant : variantManager.searchVariant(new VariantSearch(item.getTestCaseId()))) {
					new DefaultTreeNode((variant.getVariantType().equals(VariantTypes.FAILURE)) ? NODE_TYPE_FAILURE_VARIANT : NODE_TYPE_SUCCESS_VARIANT, variant, itemNode);
				}
			}
			if (0 != item.getActionPlanId()) { // Map cases.
				getTreeFromActionPlan(item.getActionPlanId(), itemNode);
			}
		}
	}

	/**
	 * Getter for the private field value root.
	 * 
	 * @return the root field value.
	 */
	public TreeNode getRoot() {
		if (null == root) {
			LOGGER.debug("getRoot(): initialization.");
			root = new DefaultTreeNode("Root", null);
			TreeNode highLevelGoal = new DefaultTreeNode(NODE_TYPE_MAP, currentHierarchy.getHighLevelGoal(), root);
			try {
				getTreeFromActionPlan(currentHierarchy.getActionPlanId(), highLevelGoal);
			} catch (ItemSearchManagerException e) {
				LOGGER.error("Error during the recovery of the current action plan items.", e);
			} catch (VariantSearchManagerException e) {
				LOGGER.error("Error during the recovery of the variants of an item.", e);
			}
		}
		return root;
	}

	/**
	 * Setting a value to the root field.
	 * 
	 * @param root the value to set.
	 */
	public void setRoot(TreeNode root) {
		this.root = root;
	}

	/**
	 * Getter for the private field value selectedNode.
	 * 
	 * @return the selectedNode field value.
	 */
	public TreeNode getSelectedNode() {
		return selectedNode;
	}

	/**
	 * Setting a value to the selectedNode field.
	 * 
	 * @param selectedNode the value to set.
	 */
	public void setSelectedNode(TreeNode selectedNode) {
		this.selectedNode = selectedNode;
	}

	/**
	 * Getter for the private field value currentHierarchy.
	 * 
	 * @return the currentHierarchy field value.
	 */
	public Hierarchy getCurrentHierarchy() {
		return currentHierarchy;
	}

	/**
	 * Setting a value to the currentHierarchy field.
	 * 
	 * @param currentHierarchy the value to set.
	 */
	public void setCurrentHierarchy(Hierarchy currentHierarchy) {
		this.currentHierarchy = currentHierarchy;
	}

	/**
	 * Getter for the private field value actionManager.
	 * 
	 * @return the actionManager field value.
	 */
	public ActionManager getActionManager() {
		return actionManager;
	}

	/**
	 * Setting a value to the actionManager field.
	 * 
	 * @param actionManager the value to set.
	 */
	public void setActionManager(ActionManager actionManager) {
		this.actionManager = actionManager;
	}

	/**
	 * Getter for the private field value intentionToCollect.
	 * 
	 * @return the intentionToCollect field value.
	 */
	public Intention getIntentionToCollect() {
		return intentionToCollect;
	}

	/**
	 * Setting a value to the intentionToCollect field.
	 * 
	 * @param intentionToCollect the value to set.
	 */
	public void setIntentionToCollect(Intention intentionToCollect) {
		this.intentionToCollect = intentionToCollect;
	}

	/**
	 * Getter for the private field value sectionToCollect.
	 * 
	 * @return the sectionToCollect field value.
	 */
	public Section getSectionToCollect() {
		return sectionToCollect;
	}

	/**
	 * Setting a value to the sectionToCollect field.
	 * 
	 * @param sectionToCollect the value to set.
	 */
	public void setSectionToCollect(Section sectionToCollect) {
		this.sectionToCollect = sectionToCollect;
	}

	/**
	 * Getter for the private field value intentionsToAdd.
	 * 
	 * @return the intentionsToAdd field value.
	 */
	public List<Intention> getIntentionsToAdd() {
		return intentionsToAdd;
	}

	/**
	 * Setting a value to the intentionsToAdd field.
	 * 
	 * @param intentionsToAdd the value to set.
	 */
	public void setIntentionsToAdd(List<Intention> intentionsToAdd) {
		this.intentionsToAdd = intentionsToAdd;
	}

	/**
	 * Getter for the private field value sectionsToAdd.
	 * 
	 * @return the sectionsToAdd field value.
	 */
	public List<Section> getSectionsToAdd() {
		return sectionsToAdd;
	}

	/**
	 * Setting a value to the sectionsToAdd field.
	 * 
	 * @param sectionsToAdd the value to set.
	 */
	public void setSectionsToAdd(List<Section> sectionsToAdd) {
		this.sectionsToAdd = sectionsToAdd;
	}

	/**
	 * Getter for the private field value actionExistingFromCurrentMap.
	 * 
	 * @return the actionExistingFromCurrentMap field value.
	 */
	public Boolean getActionExistingFromCurrentMap() {
		if (null == actionExistingFromCurrentMap) {
			LOGGER.debug("getActionExistingFromCurrentMap(): initialization.");
			try {
				actionExistingFromCurrentMap = actionManager.isActionExistingFromActionPlanId(currentActionPlanId);
			} catch (ActionSearchManagerException e) {
				LOGGER.error("Error during the checking of the actions existance for the current action plan.", e);
			}
		}
		return actionExistingFromCurrentMap;
	}

	/**
	 * Setting a value to the actionExistingFromCurrentMap field.
	 * 
	 * @param actionExistingFromCurrentMap the value to set.
	 */
	public void setActionExistingFromCurrentMap(Boolean actionExistingFromCurrentMap) {
		this.actionExistingFromCurrentMap = actionExistingFromCurrentMap;
	}

	/**
	 * Getter for the private field value errorIntentionOrSectionNumber.
	 * 
	 * @return the errorIntentionOrSectionNumber field value.
	 */
	public boolean isErrorIntentionOrSectionNumber() {
		return errorIntentionOrSectionNumber;
	}

	/**
	 * Setting a value to the errorIntentionOrSectionNumber field.
	 * 
	 * @param errorIntentionOrSectionNumber the value to set.
	 */
	public void setErrorIntentionOrSectionNumber(boolean errorIntentionOrSectionNumber) {
		this.errorIntentionOrSectionNumber = errorIntentionOrSectionNumber;
	}

	/**
	 * Getter for the private field value errorMaxIterationNumberMissing.
	 * 
	 * @return the errorMaxIterationNumberMissing field value.
	 */
	public boolean isErrorMaxIterationNumberMissing() {
		return errorMaxIterationNumberMissing;
	}

	/**
	 * Setting a value to the errorMaxIterationNumberMissing field.
	 * 
	 * @param errorMaxIterationNumberMissing the value to set.
	 */
	public void setErrorMaxIterationNumberMissing(boolean errorMaxIterationNumberMissing) {
		this.errorMaxIterationNumberMissing = errorMaxIterationNumberMissing;
	}

	/**
	 * Getter for the private field value errorStartOrStopIntentionMissing.
	 * 
	 * @return the errorStartOrStopIntentionMissing field value.
	 */
	public boolean isErrorStartOrStopIntentionMissing() {
		return errorStartOrStopIntentionMissing;
	}

	/**
	 * Setting a value to the errorStartOrStopIntentionMissing field.
	 * 
	 * @param errorStartOrStopIntentionMissing the value to set.
	 */
	public void setErrorStartOrStopIntentionMissing(boolean errorStartOrStopIntentionMissing) {
		this.errorStartOrStopIntentionMissing = errorStartOrStopIntentionMissing;
	}

	/**
	 * Getter for the private field value errorIsolatedIntention.
	 * 
	 * @return the errorIsolatedIntention field value.
	 */
	public boolean isErrorIsolatedIntention() {
		return errorIsolatedIntention;
	}

	/**
	 * Setting a value to the errorIsolatedIntention field.
	 * 
	 * @param errorIsolatedIntention the value to set.
	 */
	public void setErrorIsolatedIntention(boolean errorIsolatedIntention) {
		this.errorIsolatedIntention = errorIsolatedIntention;
	}

	/**
	 * Getter for the private field value errorIsolatedExclusiveSection.
	 * 
	 * @return the errorIsolatedExclusiveSection field value.
	 */
	public boolean isErrorIsolatedExclusiveSection() {
		return errorIsolatedExclusiveSection;
	}

	/**
	 * Setting a value to the errorIsolatedExclusiveSection field.
	 * 
	 * @param errorIsolatedExclusiveSection the value to set.
	 */
	public void setErrorIsolatedExclusiveSection(boolean errorIsolatedExclusiveSection) {
		this.errorIsolatedExclusiveSection = errorIsolatedExclusiveSection;
	}

	/**
	 * Getter for the private field value errorStartIntention.
	 * 
	 * @return the errorStartIntention field value.
	 */
	public boolean isErrorStartIntention() {
		return errorStartIntention;
	}

	/**
	 * Setting a value to the errorStartIntention field.
	 * 
	 * @param errorStartIntention the value to set.
	 */
	public void setErrorStartIntention(boolean errorStartIntention) {
		this.errorStartIntention = errorStartIntention;
	}

	/**
	 * Getter for the private field value errorStopIntention.
	 * 
	 * @return the errorStopIntention field value.
	 */
	public boolean isErrorStopIntention() {
		return errorStopIntention;
	}

	/**
	 * Setting a value to the errorStopIntention field.
	 * 
	 * @param errorStopIntention the value to set.
	 */
	public void setErrorStopIntention(boolean errorStopIntention) {
		this.errorStopIntention = errorStopIntention;
	}

	/**
	 * Getter for the private field value itemManager.
	 * 
	 * @return the itemManager field value.
	 */
	public ItemManager getItemManager() {
		return itemManager;
	}

	/**
	 * Setting a value to the itemManager field.
	 * 
	 * @param itemManager the value to set.
	 */
	public void setItemManager(ItemManager itemManager) {
		this.itemManager = itemManager;
	}

	/**
	 * Getter for the private field value selectedIntentions.
	 * 
	 * @return the selectedIntentions field value.
	 */
	public Intention[] getSelectedIntentions() {
		return selectedIntentions;
	}

	/**
	 * Setting a value to the selectedIntentions field.
	 * 
	 * @param selectedIntentions the value to set.
	 */
	public void setSelectedIntentions(Intention[] selectedIntentions) {
		this.selectedIntentions = selectedIntentions;
	}

	/**
	 * Getter for the private field value currentActionPlanId.
	 * 
	 * @return the currentActionPlanId field value.
	 */
	public int getCurrentActionPlanId() {
		return currentActionPlanId;
	}

	/**
	 * Setting a value to the currentActionPlanId field.
	 * 
	 * @param currentActionPlanId the value to set.
	 */
	public void setCurrentActionPlanId(int currentActionPlanId) {
		this.currentActionPlanId = currentActionPlanId;
	}

	/**
	 * Getter for the private field value currentTestCaseId.
	 * 
	 * @return the currentTestCaseId field value.
	 */
	public int getCurrentTestCaseId() {
		return currentTestCaseId;
	}

	/**
	 * Setting a value to the currentTestCaseId field.
	 * 
	 * @param currentTestCaseId the value to set.
	 */
	public void setCurrentTestCaseId(int currentTestCaseId) {
		this.currentTestCaseId = currentTestCaseId;
	}

	/**
	 * Getter for the private field value intentions.
	 * 
	 * @return the intentions field value.
	 */
	public List<Intention> getIntentions() {
		if (null == intentions) {
			LOGGER.debug("getIntentions(): initialization.");
			try {
				intentions = intentionManager.searchIntention(new IntentionSearch(currentActionPlanId));
			} catch (IntentionSearchManagerException e) {
				LOGGER.error("Error during the recovery of the intentions.", e);
			}
		}
		return intentions;
	}

	/**
	 * Setting a value to the intentions field.
	 * 
	 * @param intentions the value to set.
	 */
	public void setIntentions(List<Intention> intentions) {
		this.intentions = intentions;
	}

	/**
	 * Getter for the private field value intentionManager.
	 * 
	 * @return the intentionManager field value.
	 */
	public IntentionManager getIntentionManager() {
		return intentionManager;
	}

	/**
	 * Setting a value to the intentionManager field.
	 * 
	 * @param intentionManager the value to set.
	 */
	public void setIntentionManager(IntentionManager intentionManager) {
		this.intentionManager = intentionManager;
	}

	/**
	 * Getter for the private field value nodeTypeItem.
	 * 
	 * @return the nodeTypeItem field value.
	 */
	public String getNodeTypeItem() {
		return NODE_TYPE_ITEM;
	}

	/**
	 * Getter for the private field value nodeTypeMap.
	 * 
	 * @return the nodeTypeMap field value.
	 */
	public String getNodeTypeMap() {
		return NODE_TYPE_MAP;
	}

	/**
	 * Getter for the private field value nodeTypeProcedural.
	 * 
	 * @return the nodeTypeProcedural field value.
	 */
	public String getNodeTypeProcedural() {
		return NODE_TYPE_PROCEDURAL;
	}

	/**
	 * Getter for the private field value selectedItems.
	 * 
	 * @return the selectedItems field value.
	 */
	public Item[] getSelectedItems() {
		return selectedItems;
	}

	/**
	 * Setting a value to the selectedItems field.
	 * 
	 * @param selectedItems the value to set.
	 */
	public void setSelectedItems(Item[] selectedItems) {
		this.selectedItems = selectedItems;
	}

	/**
	 * Getter for the private field value items.
	 * 
	 * @return the items field value.
	 */
	public List<Item> getItems() {
		if (null == items) {
			LOGGER.debug("getItems(): initialization.");
			try {
				items = itemManager.searchItem(new ItemSearch(currentActionPlanId));
			} catch (ItemSearchManagerException e) {
				LOGGER.error("Error during the recovery of the items.", e);
			}
		}
		return items;
	}

	/**
	 * Setting a value to the items field.
	 * 
	 * @param items the value to set.
	 */
	public void setItems(List<Item> items) {
		this.items = items;
	}

	/**
	 * Getter for the private field value mapDiagram.
	 * 
	 * @return the mapDiagram field value.
	 */
	public StreamedContent getMapDiagram() {
		if (null == mapDiagram) {
			LOGGER.debug("getMapDiagram(): initialization.");
			DirectedGraph<Intention, MapArrow> noColorizedDiagram = mapDiagramManager.createMapDiagramFromIntentionsAndItems(getIntentions(), getItems());
			BufferedImage bImage = new BufferedImage(ColorUtil.REDUCE_SIZE.width, ColorUtil.REDUCE_SIZE.height, BufferedImage.TYPE_INT_RGB);
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			Graphics2D g2d = bImage.createGraphics();
			DiagramGraphistUtil.getColorizedMapDiagram(noColorizedDiagram).paint(g2d);
			try {
				ImageIO.write(bImage, PNG_TYPE, baos);
				mapDiagram = new DefaultStreamedContent(new ByteArrayInputStream(baos.toByteArray()), IMAGE_PNG_TYPE);
			} catch (IOException e) {
				LOGGER.error("Error during the map diagram generation.", e);
			}
		}
		return mapDiagram;
	}

	/**
	 * Setting a value to the mapDiagram field.
	 * 
	 * @param mapDiagram the value to set.
	 */
	public void setMapDiagram(StreamedContent mapDiagram) {
		this.mapDiagram = mapDiagram;
	}

	/**
	 * Getter for the private field value proceduralDiagram.
	 * 
	 * @return the proceduralDiagram field value.
	 */
	public StreamedContent getProceduralDiagram() {
		if (null == proceduralDiagram) {
			LOGGER.debug("getProceduralDiagram(): initialization.");
			DirectedGraph<Element, ProceduralArrow> noColorizedproceduralDiagram = proceduralDiagramManager.createProceduralDiagramFromElementsAndTransitions(getElements(), getTransitions());
			BufferedImage bImage = new BufferedImage(ColorUtil.REDUCE_SIZE.width, ColorUtil.REDUCE_SIZE.height, BufferedImage.TYPE_INT_RGB);
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			Graphics2D g2d = bImage.createGraphics();
			DiagramGraphistUtil.getColorizedProceduralDiagram(noColorizedproceduralDiagram).paint(g2d);
			try {
				ImageIO.write(bImage, PNG_TYPE, baos);
				proceduralDiagram = new DefaultStreamedContent(new ByteArrayInputStream(baos.toByteArray()), IMAGE_PNG_TYPE);
			} catch (IOException e) {
				LOGGER.error("Error during the procedural diagram generation.", e);
			}
		}
		return proceduralDiagram;
	}

	/**
	 * Setting a value to the proceduralDiagram field.
	 * 
	 * @param proceduralDiagram the value to set.
	 */
	public void setProceduralDiagram(StreamedContent proceduralDiagram) {
		this.proceduralDiagram = proceduralDiagram;
	}

	/**
	 * Getter for the private field value mapDiagramManager.
	 * 
	 * @return the mapDiagramManager field value.
	 */
	public MapDiagramManager getMapDiagramManager() {
		return mapDiagramManager;
	}

	/**
	 * Setting a value to the mapDiagramManager field.
	 * 
	 * @param mapDiagramManager the value to set.
	 */
	public void setMapDiagramManager(MapDiagramManager mapDiagramManager) {
		this.mapDiagramManager = mapDiagramManager;
	}

	/**
	 * Getter for the private field value elementExistingFromCurrentDiagram.
	 * 
	 * @return the elementExistingFromCurrentDiagram field value.
	 */
	public Boolean getElementExistingFromCurrentDiagram() {
		if (null == elementExistingFromCurrentDiagram) {
			LOGGER.debug("getElementExistingFromCurrentDiagram(): initialization.");
			try {
				elementExistingFromCurrentDiagram = elementManager.isElementExistingFromCaseTestId(currentTestCaseId);
			} catch (ElementSearchManagerException e) {
				LOGGER.error("Error during the checking of the test case existance.", e);
			}
		}
		return elementExistingFromCurrentDiagram;
	}

	/**
	 * Setting a value to the elementExistingFromCurrentDiagram field.
	 * 
	 * @param elementExistingFromCurrentDiagram the value to set.
	 */
	public void setElementExistingFromCurrentDiagram(Boolean elementExistingFromCurrentDiagram) {
		this.elementExistingFromCurrentDiagram = elementExistingFromCurrentDiagram;
	}

	/**
	 * Getter for the private field value elementManager.
	 * 
	 * @return the elementManager field value.
	 */
	public ElementManager getElementManager() {
		return elementManager;
	}

	/**
	 * Setting a value to the elementManager field.
	 * 
	 * @param elementManager the value to set.
	 */
	public void setElementManager(ElementManager elementManager) {
		this.elementManager = elementManager;
	}

	/**
	 * Getter for the private field value elementToCollect.
	 * 
	 * @return the elementToCollect field value.
	 */
	public ElementCreation getElementToCollect() {
		return elementToCollect;
	}

	/**
	 * Setting a value to the elementToCollect field.
	 * 
	 * @param elementToCollect the value to set.
	 */
	public void setElementToCollect(ElementCreation elementToCollect) {
		this.elementToCollect = elementToCollect;
	}

	/**
	 * Getter for the private field value elementsToAdd.
	 * 
	 * @return the elementsToAdd field value.
	 */
	public List<ElementCreation> getElementsToAdd() {
		return elementsToAdd;
	}

	/**
	 * Setting a value to the elementsToAdd field.
	 * 
	 * @param elementsToAdd the value to set.
	 */
	public void setElementsToAdd(List<ElementCreation> elementsToAdd) {
		this.elementsToAdd = elementsToAdd;
	}

	/**
	 * Getter for the private field value transitionsToAdd.
	 * 
	 * @return the transitionsToAdd field value.
	 */
	public List<TransitionCreation> getTransitionsToAdd() {
		return transitionsToAdd;
	}

	/**
	 * Setting a value to the transitionsToAdd field.
	 * 
	 * @param transitionsToAdd the value to set.
	 */
	public void setTransitionsToAdd(List<TransitionCreation> transitionsToAdd) {
		this.transitionsToAdd = transitionsToAdd;
	}

	/**
	 * Getter for the private field value transitionToCollect.
	 * 
	 * @return the transitionToCollect field value.
	 */
	public TransitionCreation getTransitionToCollect() {
		return transitionToCollect;
	}

	/**
	 * Setting a value to the transitionToCollect field.
	 * 
	 * @param transitionToCollect the value to set.
	 */
	public void setTransitionToCollect(TransitionCreation transitionToCollect) {
		this.transitionToCollect = transitionToCollect;
	}

	/**
	 * Getter for the private field value errorElementOrTransitionNumber.
	 * 
	 * @return the errorElementOrTransitionNumber field value.
	 */
	public boolean isErrorElementOrTransitionNumber() {
		return errorElementOrTransitionNumber;
	}

	/**
	 * Setting a value to the errorElementOrTransitionNumber field.
	 * 
	 * @param errorElementOrTransitionNumber the value to set.
	 */
	public void setErrorElementOrTransitionNumber(boolean errorElementOrTransitionNumber) {
		this.errorElementOrTransitionNumber = errorElementOrTransitionNumber;
	}

	/**
	 * Getter for the private field value errorIsolatedElement.
	 * 
	 * @return the errorIsolatedElement field value.
	 */
	public boolean isErrorIsolatedElement() {
		return errorIsolatedElement;
	}

	/**
	 * Setting a value to the errorIsolatedElement field.
	 * 
	 * @param errorIsolatedElement the value to set.
	 */
	public void setErrorIsolatedElement(boolean errorIsolatedElement) {
		this.errorIsolatedElement = errorIsolatedElement;
	}

	/**
	 * Getter for the private field value errorMissingElement.
	 * 
	 * @return the errorMissingElement field value.
	 */
	public boolean isErrorMissingElement() {
		return errorMissingElement;
	}

	/**
	 * Setting a value to the errorMissingElement field.
	 * 
	 * @param errorMissingElement the value to set.
	 */
	public void setErrorMissingElement(boolean errorMissingElement) {
		this.errorMissingElement = errorMissingElement;
	}

	/**
	 * Getter for the private field value errorMissingStartOrStopElement.
	 * 
	 * @return the errorMissingStartOrStopElement field value.
	 */
	public boolean isErrorMissingStartOrStopElement() {
		return errorMissingStartOrStopElement;
	}

	/**
	 * Setting a value to the errorMissingStartOrStopElement field.
	 * 
	 * @param errorMissingStartOrStopElement the value to set.
	 */
	public void setErrorMissingStartOrStopElement(boolean errorMissingStartOrStopElement) {
		this.errorMissingStartOrStopElement = errorMissingStartOrStopElement;
	}

	/**
	 * Getter for the private field value errorOptionMissingAfterChoice.
	 * 
	 * @return the errorOptionMissingAfterChoice field value.
	 */
	public boolean isErrorOptionMissingAfterChoice() {
		return errorOptionMissingAfterChoice;
	}

	/**
	 * Setting a value to the errorOptionMissingAfterChoice field.
	 * 
	 * @param errorOptionMissingAfterChoice the value to set.
	 */
	public void setErrorOptionMissingAfterChoice(boolean errorOptionMissingAfterChoice) {
		this.errorOptionMissingAfterChoice = errorOptionMissingAfterChoice;
	}

	/**
	 * Getter for the private field value errorSourceEqualsTarget.
	 * 
	 * @return the errorSourceEqualsTarget field value.
	 */
	public boolean isErrorSourceEqualsTarget() {
		return errorSourceEqualsTarget;
	}

	/**
	 * Setting a value to the errorSourceEqualsTarget field.
	 * 
	 * @param errorSourceEqualsTarget the value to set.
	 */
	public void setErrorSourceEqualsTarget(boolean errorSourceEqualsTarget) {
		this.errorSourceEqualsTarget = errorSourceEqualsTarget;
	}

	/**
	 * Getter for the private field value errorTransitionNumberOnChoice.
	 * 
	 * @return the errorTransitionNumberOnChoice field value.
	 */
	public boolean isErrorTransitionNumberOnChoice() {
		return errorTransitionNumberOnChoice;
	}

	/**
	 * Setting a value to the errorTransitionNumberOnChoice field.
	 * 
	 * @param errorTransitionNumberOnChoice the value to set.
	 */
	public void setErrorTransitionNumberOnChoice(boolean errorTransitionNumberOnChoice) {
		this.errorTransitionNumberOnChoice = errorTransitionNumberOnChoice;
	}

	/**
	 * Getter for the private field value errorTransitionNumberOnJoin.
	 * 
	 * @return the errorTransitionNumberOnJoin field value.
	 */
	public boolean isErrorTransitionNumberOnJoin() {
		return errorTransitionNumberOnJoin;
	}

	/**
	 * Setting a value to the errorTransitionNumberOnJoin field.
	 * 
	 * @param errorTransitionNumberOnJoin the value to set.
	 */
	public void setErrorTransitionNumberOnJoin(boolean errorTransitionNumberOnJoin) {
		this.errorTransitionNumberOnJoin = errorTransitionNumberOnJoin;
	}

	/**
	 * Getter for the private field value errorStartElement.
	 * 
	 * @return the errorStartElement field value.
	 */
	public boolean isErrorStartElement() {
		return errorStartElement;
	}

	/**
	 * Setting a value to the errorStartElement field.
	 * 
	 * @param errorStartElement the value to set.
	 */
	public void setErrorStartElement(boolean errorStartElement) {
		this.errorStartElement = errorStartElement;
	}

	/**
	 * Getter for the private field value errorStopElement.
	 * 
	 * @return the errorStopElement field value.
	 */
	public boolean isErrorStopElement() {
		return errorStopElement;
	}

	/**
	 * Setting a value to the errorStopElement field.
	 * 
	 * @param errorStopElement the value to set.
	 */
	public void setErrorStopElement(boolean errorStopElement) {
		this.errorStopElement = errorStopElement;
	}

	/**
	 * Getter for the private field value errorMultipleTransitions.
	 * 
	 * @return the errorMultipleTransitions field value.
	 */
	public boolean isErrorMultipleTransitions() {
		return errorMultipleTransitions;
	}

	/**
	 * Setting a value to the errorMultipleTransitions field.
	 * 
	 * @param errorMultipleTransitions the value to set.
	 */
	public void setErrorMultipleTransitions(boolean errorMultipleTransitions) {
		this.errorMultipleTransitions = errorMultipleTransitions;
	}

	/**
	 * Getter for the private field value errorMultipleSources.
	 * 
	 * @return the errorMultipleSources field value.
	 */
	public boolean isErrorMultipleSources() {
		return errorMultipleSources;
	}

	/**
	 * Setting a value to the errorMultipleSources field.
	 * 
	 * @param errorMultipleSources the value to set.
	 */
	public void setErrorMultipleSources(boolean errorMultipleSources) {
		this.errorMultipleSources = errorMultipleSources;
	}

	/**
	 * Getter for the private field value elements.
	 * 
	 * @return the elements field value.
	 */
	public List<Element> getElements() {
		if (null == elements) {
			LOGGER.debug("getElements(): initialization.");
			try {
				elements = elementManager.searchElement(new ElementSearch(currentTestCaseId));
			} catch (ElementSearchManagerException e) {
				LOGGER.error("Error during the elements recovery.", e);
			}
		}
		return elements;
	}

	/**
	 * Setting a value to the elements field.
	 * 
	 * @param elements the value to set.
	 */
	public void setElements(List<Element> elements) {
		this.elements = elements;
	}

	/**
	 * Getter for the private field value selectedElements.
	 * 
	 * @return the selectedElements field value.
	 */
	public Element[] getSelectedElements() {
		return selectedElements;
	}

	/**
	 * Setting a value to the selectedElements field.
	 * 
	 * @param selectedElements the value to set.
	 */
	public void setSelectedElements(Element[] selectedElements) {
		this.selectedElements = selectedElements;
	}

	/**
	 * Getter for the private field value selectedTransitions.
	 * 
	 * @return the selectedTransitions field value.
	 */
	public Transition[] getSelectedTransitions() {
		return selectedTransitions;
	}

	/**
	 * Setting a value to the selectedTransitions field.
	 * 
	 * @param selectedTransitions the value to set.
	 */
	public void setSelectedTransitions(Transition[] selectedTransitions) {
		this.selectedTransitions = selectedTransitions;
	}

	/**
	 * Getter for the private field value transitions.
	 * 
	 * @return the transitions field value.
	 */
	public List<Transition> getTransitions() {
		if (null == transitions) {
			LOGGER.debug("getTransitions().");
			try {
				transitions = transitionManager.searchTransition(new TransitionSearch(currentTestCaseId));
			} catch (TransitionSearchManagerException e) {
				LOGGER.error("Error during the transitions recovery.", e);
			}
		}
		return transitions;
	}

	/**
	 * Setting a value to the transitions field.
	 * 
	 * @param transitions the value to set.
	 */
	public void setTransitions(List<Transition> transitions) {
		this.transitions = transitions;
	}

	/**
	 * Getter for the private field value transitionManager.
	 * 
	 * @return the transitionManager field value.
	 */
	public TransitionManager getTransitionManager() {
		return transitionManager;
	}

	/**
	 * Setting a value to the transitionManager field.
	 * 
	 * @param transitionManager the value to set.
	 */
	public void setTransitionManager(TransitionManager transitionManager) {
		this.transitionManager = transitionManager;
	}

	/**
	 * Getter for the private field value proceduralDiagramManager.
	 * 
	 * @return the proceduralDiagramManager field value.
	 */
	public ProceduralDiagramManager getProceduralDiagramManager() {
		return proceduralDiagramManager;
	}

	/**
	 * Setting a value to the proceduralDiagramManager field.
	 * 
	 * @param proceduralDiagramManager the value to set.
	 */
	public void setProceduralDiagramManager(ProceduralDiagramManager proceduralDiagramManager) {
		this.proceduralDiagramManager = proceduralDiagramManager;
	}

	/**
	 * Getter for the private field value activitiesToDescribe.
	 * 
	 * @return the activitiesToDescribe field value.
	 */
	public List<Activity> getActivitiesToDescribe() {
		if (null == activitiesToDescribe) {
			LOGGER.debug("getActivitiesToDescribe(): initialization.");
			try {
				activitiesToDescribe = activityManager.searchActivitiesToDescribeFromTestCaseId(currentTestCaseId);
			} catch (ActivitySearchManagerException e) {
				LOGGER.error("Error during the recovery of the activities to describe for a given test case.", e);
			}
		}
		return activitiesToDescribe;
	}

	/**
	 * Setting a value to the activitiesToDescribe field.
	 * 
	 * @param activitiesToDescribe the value to set.
	 */
	public void setActivitiesToDescribe(List<Activity> activitiesToDescribe) {
		this.activitiesToDescribe = activitiesToDescribe;
	}

	/**
	 * Getter for the private field value activityManager.
	 * 
	 * @return the activityManager field value.
	 */
	public ActivityManager getActivityManager() {
		return activityManager;
	}

	/**
	 * Setting a value to the activityManager field.
	 * 
	 * @param activityManager the value to set.
	 */
	public void setActivityManager(ActivityManager activityManager) {
		this.activityManager = activityManager;
	}

	/**
	 * Getter for the private field value fullMapDiagram.
	 * 
	 * @return the fullMapDiagram field value.
	 */
	public StreamedContent getFullMapDiagram() {
		if (null == fullMapDiagram && null != intentions && !intentions.isEmpty() && null != items && !items.isEmpty()) {
			LOGGER.debug("getFullMapDiagram(): initialization.");
			DirectedGraph<Intention, MapArrow> noColorizedDiagram = mapDiagramManager.createMapDiagramFromIntentionsAndItems(getIntentions(), getItems());
			BufferedImage bImage = new BufferedImage(ColorUtil.FULL_SCREEN_SIZE.width, ColorUtil.FULL_SCREEN_SIZE.height, BufferedImage.TYPE_INT_RGB);
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			Graphics2D g2d = bImage.createGraphics();
			DiagramGraphistUtil.getColorizedMapDiagramFromAlgorithmAndSize(noColorizedDiagram, currentMapAlgorithm, ColorUtil.FULL_SCREEN_SIZE).paint(g2d);
			try {
				ImageIO.write(bImage, PNG_TYPE, baos);
				fullMapDiagram = new DefaultStreamedContent(new ByteArrayInputStream(baos.toByteArray()), IMAGE_PNG_TYPE);
			} catch (IOException e) {
				LOGGER.error("Error during the map diagram generation.", e);
			}
		}
		return fullMapDiagram;
	}

	/**
	 * Setting a value to the fullMapDiagram field.
	 * 
	 * @param fullMapDiagram the value to set.
	 */
	public void setFullMapDiagram(StreamedContent fullMapDiagram) {
		this.fullMapDiagram = fullMapDiagram;
	}

	/**
	 * Getter for the private field value fullProceduralDiagram.
	 * 
	 * @return the fullProceduralDiagram field value.
	 */
	public StreamedContent getFullProceduralDiagram() {
		if (null == fullProceduralDiagram && null != elements && !elements.isEmpty() && null != transitions && !transitions.isEmpty()) {
			LOGGER.debug("getFullProceduralDiagram(): initialization.");
			DirectedGraph<Element, ProceduralArrow> noColorizedproceduralDiagram = proceduralDiagramManager.createProceduralDiagramFromElementsAndTransitions(getElements(), getTransitions());
			BufferedImage bImage = new BufferedImage(ColorUtil.FULL_SCREEN_SIZE.width, ColorUtil.FULL_SCREEN_SIZE.height, BufferedImage.TYPE_INT_RGB);
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			Graphics2D g2d = bImage.createGraphics();
			DiagramGraphistUtil.getColorizedProceduralDiagramFromAlgorithmAndSize(noColorizedproceduralDiagram, currentProceduralAlgorithm, ColorUtil.FULL_SCREEN_SIZE).paint(g2d);
			try {
				ImageIO.write(bImage, PNG_TYPE, baos);
				fullProceduralDiagram = new DefaultStreamedContent(new ByteArrayInputStream(baos.toByteArray()), IMAGE_PNG_TYPE);
			} catch (IOException e) {
				LOGGER.error("Error during the procedural diagram generation.", e);
			}
		}
		return fullProceduralDiagram;
	}

	/**
	 * Setting a value to the fullProceduralDiagram field.
	 * 
	 * @param fullProceduralDiagram the value to set.
	 */
	public void setFullProceduralDiagram(StreamedContent fullProceduralDiagram) {
		this.fullProceduralDiagram = fullProceduralDiagram;
	}

	/**
	 * Getter for the private field value currentMapAlgorithm.
	 * 
	 * @return the currentMapAlgorithm field value.
	 */
	public DrawingAlgorithm getCurrentMapAlgorithm() {
		return currentMapAlgorithm;
	}

	/**
	 * Setting a value to the currentMapAlgorithm field.
	 * 
	 * @param currentMapAlgorithm the value to set.
	 */
	public void setCurrentMapAlgorithm(DrawingAlgorithm currentMapAlgorithm) {
		this.currentMapAlgorithm = currentMapAlgorithm;
	}

	/**
	 * Getter for the private field value currentProceduralAlgorithm.
	 * 
	 * @return the currentProceduralAlgorithm field value.
	 */
	public DrawingAlgorithm getCurrentProceduralAlgorithm() {
		return currentProceduralAlgorithm;
	}

	/**
	 * Setting a value to the currentProceduralAlgorithm field.
	 * 
	 * @param currentProceduralAlgorithm the value to set.
	 */
	public void setCurrentProceduralAlgorithm(DrawingAlgorithm currentProceduralAlgorithm) {
		this.currentProceduralAlgorithm = currentProceduralAlgorithm;
	}

	/**
	 * Getter for the private field value oldMapAlgorithm.
	 * 
	 * @return the oldMapAlgorithm field value.
	 */
	public DrawingAlgorithm getOldMapAlgorithm() {
		return oldMapAlgorithm;
	}

	/**
	 * Setting a value to the oldMapAlgorithm field.
	 * 
	 * @param oldMapAlgorithm the value to set.
	 */
	public void setOldMapAlgorithm(DrawingAlgorithm oldMapAlgorithm) {
		this.oldMapAlgorithm = oldMapAlgorithm;
	}

	/**
	 * Getter for the private field value oldProceduralAlgorithm.
	 * 
	 * @return the oldProceduralAlgorithm field value.
	 */
	public DrawingAlgorithm getOldProceduralAlgorithm() {
		return oldProceduralAlgorithm;
	}

	/**
	 * Setting a value to the oldProceduralAlgorithm field.
	 * 
	 * @param oldProceduralAlgorithm the value to set.
	 */
	public void setOldProceduralAlgorithm(DrawingAlgorithm oldProceduralAlgorithm) {
		this.oldProceduralAlgorithm = oldProceduralAlgorithm;
	}

	/**
	 * Getter for the private field value drawingAlgorithmsAsSelectItem.
	 * 
	 * @return the drawingAlgorithmsAsSelectItem field value.
	 */
	public List<SelectItem> getDrawingAlgorithmsAsSelectItem() {
		if (null == drawingAlgorithmsAsSelectItem) {
			LOGGER.debug("getDrawingAlgorithmsAsSelectItem(): initialization.");
			drawingAlgorithmsAsSelectItem = new ArrayList<SelectItem>();
			drawingAlgorithmsAsSelectItem.add(new SelectItem(DrawingAlgorithm.CIRCLE, DrawingAlgorithm.CIRCLE.name()));
			drawingAlgorithmsAsSelectItem.add(new SelectItem(DrawingAlgorithm.FR, DrawingAlgorithm.FR.name()));
			drawingAlgorithmsAsSelectItem.add(new SelectItem(DrawingAlgorithm.FR2, DrawingAlgorithm.FR2.name()));
			drawingAlgorithmsAsSelectItem.add(new SelectItem(DrawingAlgorithm.ISOM, DrawingAlgorithm.ISOM.name()));
			drawingAlgorithmsAsSelectItem.add(new SelectItem(DrawingAlgorithm.KK, DrawingAlgorithm.KK.name()));
			drawingAlgorithmsAsSelectItem.add(new SelectItem(DrawingAlgorithm.SPRING, DrawingAlgorithm.SPRING.name()));
			drawingAlgorithmsAsSelectItem.add(new SelectItem(DrawingAlgorithm.SPRING2, DrawingAlgorithm.SPRING2.name()));
		}
		return drawingAlgorithmsAsSelectItem;
	}

	/**
	 * Setting a value to the drawingAlgorithmsAsSelectItem field.
	 * 
	 * @param drawingAlgorithmsAsSelectItem the value to set.
	 */
	public void setDrawingAlgorithmsAsSelectItem(List<SelectItem> drawingAlgorithmsAsSelectItem) {
		this.drawingAlgorithmsAsSelectItem = drawingAlgorithmsAsSelectItem;
	}

	/**
	 * Setting a value to the elementToAddTypesAsSelectItem field.
	 * 
	 * @param elementToAddTypesAsSelectItem the value to set.
	 */
	public void setElementToAddTypesAsSelectItem(List<SelectItem> elementToAddTypesAsSelectItem) {
		this.elementToAddTypesAsSelectItem = elementToAddTypesAsSelectItem;
	}

	/**
	 * Getter for the private field value variantManager.
	 * 
	 * @return the variantManager field value.
	 */
	public VariantManager getVariantManager() {
		return variantManager;
	}

	/**
	 * Setting a value to the variantManager field.
	 * 
	 * @param variantManager the value to set.
	 */
	public void setVariantManager(VariantManager variantManager) {
		this.variantManager = variantManager;
	}

	/**
	 * Getter for the private field value variantsExistingFromCurrentDiagram.
	 * 
	 * @return the variantsExistingFromCurrentDiagram field value.
	 */
	public Boolean getVariantsExistingFromCurrentDiagram() {
		if (null == variantsExistingFromCurrentDiagram) {
			LOGGER.debug("getVariantsExistingFromCurrentDiagram(): initialization.");
			try {
				variantsExistingFromCurrentDiagram = variantManager.areVariantsExistingFromTestCaseId(currentTestCaseId);
			} catch (VariantSearchManagerException e) {
				LOGGER.error("Error during the checking of variants existance.", e);
			}
		}
		return variantsExistingFromCurrentDiagram;
	}

	/**
	 * Setting a value to the variantsExistingFromCurrentDiagram field.
	 * 
	 * @param variantsExistingFromCurrentDiagram the value to set.
	 */
	public void setVariantsExistingFromCurrentDiagram(Boolean variantsExistingFromCurrentDiagram) {
		this.variantsExistingFromCurrentDiagram = variantsExistingFromCurrentDiagram;
	}

	/**
	 * Getter for the private field value nodeTypeFailureVariant.
	 * 
	 * @return the nodeTypeFailureVariant field value.
	 */
	public String getNodeTypeFailureVariant() {
		return NODE_TYPE_FAILURE_VARIANT;
	}

	/**
	 * Getter for the private field value nodeTypeSuccessVariant.
	 * 
	 * @return the nodeTypeSuccessVariant field value.
	 */
	public String getNodeTypeSuccessVariant() {
		return NODE_TYPE_SUCCESS_VARIANT;
	}

	/**
	 * Getter for the private field value variants.
	 * 
	 * @return the variants field value.
	 */
	public List<Variant> getVariants() {
		if (null == variants) {
			LOGGER.debug("getVariants(): initialization.");
			try {
				variants = variantManager.searchVariant(new VariantSearch(currentTestCaseId));
			} catch (VariantSearchManagerException e) {
				LOGGER.error("Error during the variants recovery.", e);
			}
		}
		return variants;
	}

	/**
	 * Setting a value to the variants field.
	 * 
	 * @param variants the value to set.
	 */
	public void setVariants(List<Variant> variants) {
		this.variants = variants;
	}

	/**
	 * Getter for the private field value currentEditingVariant.
	 * 
	 * @return the currentEditingVariant field value.
	 */
	public Variant getCurrentEditingVariant() {
		return currentEditingVariant;
	}

	/**
	 * Setting a value to the currentEditingVariant field.
	 * 
	 * @param currentEditingVariant the value to set.
	 */
	public void setCurrentEditingVariant(Variant currentEditingVariant) {
		this.currentEditingVariant = currentEditingVariant;
	}

	/**
	 * Getter for the private field value selectedVariantsElements.
	 * 
	 * @return the selectedVariantsElements field value.
	 */
	public Element[] getSelectedVariantsElements() {
		return selectedVariantsElements;
	}

	/**
	 * Setting a value to the selectedVariantsElements field.
	 * 
	 * @param selectedVariantsElements the value to set.
	 */
	public void setSelectedVariantsElements(Element[] selectedVariantsElements) {
		this.selectedVariantsElements = selectedVariantsElements;
	}

	/**
	 * Getter for the private field value variantsElements.
	 * 
	 * @return the variantsElements field value.
	 */
	public List<Element> getVariantsElements() {
		if (null == variantsElements) {
			LOGGER.debug("getVariantsElements(): initialization.");
			ElementSearch searchBean = new ElementSearch();
			searchBean.setParentVariantId(currentVariantId);
			try {
				variantsElements = elementManager.searchElement(searchBean);
			} catch (ElementSearchManagerException e) {
				LOGGER.error("Error during the recovery of a variant elements.", e);
			}
		}
		return variantsElements;
	}

	/**
	 * Setting a value to the variantsElements field.
	 * 
	 * @param variantsElements the value to set.
	 */
	public void setVariantsElements(List<Element> variantsElements) {
		this.variantsElements = variantsElements;
	}

	/**
	 * Getter for the private field value variantsTransitions.
	 * 
	 * @return the variantsTransitions field value.
	 */
	public List<Transition> getVariantsTransitions() {
		if (null == variantsTransitions) {
			LOGGER.debug("getVariantsTransitions(): initialization.");
			TransitionSearch searchBean = new TransitionSearch();
			searchBean.setParentVariantId(currentVariantId);
			try {
				variantsTransitions = transitionManager.searchTransition(searchBean);
			} catch (TransitionSearchManagerException e) {
				LOGGER.error("Error during the recovery of a variant transitions.", e);
			}
		}
		return variantsTransitions;
	}

	/**
	 * Setting a value to the variantsTransitions field.
	 * 
	 * @param variantsTransitions the value to set.
	 */
	public void setVariantsTransitions(List<Transition> variantsTransitions) {
		this.variantsTransitions = variantsTransitions;
	}

	/**
	 * Getter for the private field value selectedVariantsTransitions.
	 * 
	 * @return the selectedVariantsTransitions field value.
	 */
	public Transition[] getSelectedVariantsTransitions() {
		return selectedVariantsTransitions;
	}

	/**
	 * Setting a value to the selectedVariantsTransitions field.
	 * 
	 * @param selectedVariantsTransitions the value to set.
	 */
	public void setSelectedVariantsTransitions(Transition[] selectedVariantsTransitions) {
		this.selectedVariantsTransitions = selectedVariantsTransitions;
	}

	/**
	 * Getter for the private field value currentVariantId.
	 * 
	 * @return the currentVariantId field value.
	 */
	public int getCurrentVariantId() {
		return currentVariantId;
	}

	/**
	 * Setting a value to the currentVariantId field.
	 * 
	 * @param currentVariantId the value to set.
	 */
	public void setCurrentVariantId(int currentVariantId) {
		this.currentVariantId = currentVariantId;
	}

	/**
	 * Getter for the private field value fullVariantDiagram.
	 * 
	 * @return the fullVariantDiagram field value.
	 */
	public StreamedContent getFullVariantDiagram() {
		if (null == fullVariantDiagram && null != variantsElements && !variantsElements.isEmpty() && null != variantsTransitions && !variantsTransitions.isEmpty()) {
			LOGGER.debug("getFullVariantDiagram(): initialization.");
			DirectedGraph<Element, ProceduralArrow> noColorizedproceduralDiagram = proceduralDiagramManager.createProceduralDiagramFromElementsAndTransitions(getVariantsElements(), getVariantsTransitions());
			BufferedImage bImage = new BufferedImage(ColorUtil.FULL_SCREEN_SIZE.width, ColorUtil.FULL_SCREEN_SIZE.height, BufferedImage.TYPE_INT_RGB);
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			Graphics2D g2d = bImage.createGraphics();
			DiagramGraphistUtil.getColorizedProceduralDiagramFromAlgorithmAndSize(noColorizedproceduralDiagram, currentVariantAlgorithm, ColorUtil.FULL_SCREEN_SIZE).paint(g2d);
			try {
				ImageIO.write(bImage, PNG_TYPE, baos);
				fullVariantDiagram = new DefaultStreamedContent(new ByteArrayInputStream(baos.toByteArray()), IMAGE_PNG_TYPE);
			} catch (IOException e) {
				LOGGER.error("Error during the procedural diagram generation.", e);
			}
		}
		return fullVariantDiagram;
	}

	/**
	 * Setting a value to the fullVariantDiagram field.
	 * 
	 * @param fullVariantDiagram the value to set.
	 */
	public void setFullVariantDiagram(StreamedContent fullVariantDiagram) {
		this.fullVariantDiagram = fullVariantDiagram;
	}

	/**
	 * Getter for the private field value variantDiagram.
	 * 
	 * @return the variantDiagram field value.
	 */
	public StreamedContent getVariantDiagram() {
		if (null == variantDiagram) {
			LOGGER.debug("getVariantDiagram(): initialization.");
			DirectedGraph<Element, ProceduralArrow> noColorizedproceduralDiagram = proceduralDiagramManager.createProceduralDiagramFromElementsAndTransitions(getVariantsElements(), getVariantsTransitions());
			BufferedImage bImage = new BufferedImage(ColorUtil.REDUCE_SIZE.width, ColorUtil.REDUCE_SIZE.height, BufferedImage.TYPE_INT_RGB);
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			Graphics2D g2d = bImage.createGraphics();
			DiagramGraphistUtil.getColorizedProceduralDiagram(noColorizedproceduralDiagram).paint(g2d);
			try {
				ImageIO.write(bImage, PNG_TYPE, baos);
				variantDiagram = new DefaultStreamedContent(new ByteArrayInputStream(baos.toByteArray()), IMAGE_PNG_TYPE);
			} catch (IOException e) {
				LOGGER.error("Error during the procedural diagram generation.", e);
			}
		}
		return variantDiagram;
	}

	/**
	 * Setting a value to the variantDiagram field.
	 * 
	 * @param variantDiagram the value to set.
	 */
	public void setVariantDiagram(StreamedContent variantDiagram) {
		this.variantDiagram = variantDiagram;
	}

	/**
	 * Getter for the private field value currentVariantAlgorithm.
	 * 
	 * @return the currentVariantAlgorithm field value.
	 */
	public DrawingAlgorithm getCurrentVariantAlgorithm() {
		return currentVariantAlgorithm;
	}

	/**
	 * Setting a value to the currentVariantAlgorithm field.
	 * 
	 * @param currentVariantAlgorithm the value to set.
	 */
	public void setCurrentVariantAlgorithm(DrawingAlgorithm currentVariantAlgorithm) {
		this.currentVariantAlgorithm = currentVariantAlgorithm;
	}

	/**
	 * Getter for the private field value oldVariantAlgorithm.
	 * 
	 * @return the oldVariantAlgorithm field value.
	 */
	public DrawingAlgorithm getOldVariantAlgorithm() {
		return oldVariantAlgorithm;
	}

	/**
	 * Setting a value to the oldVariantAlgorithm field.
	 * 
	 * @param oldVariantAlgorithm the value to set.
	 */
	public void setOldVariantAlgorithm(DrawingAlgorithm oldVariantAlgorithm) {
		this.oldVariantAlgorithm = oldVariantAlgorithm;
	}

	/**
	 * Getter for the private field value errorMissingIntention.
	 * 
	 * @return the errorMissingIntention field value.
	 */
	public boolean isErrorMissingIntention() {
		return errorMissingIntention;
	}

	/**
	 * Setting a value to the errorMissingIntention field.
	 * 
	 * @param errorMissingIntention the value to set.
	 */
	public void setErrorMissingIntention(boolean errorMissingIntention) {
		this.errorMissingIntention = errorMissingIntention;
	}
}